<div class="row-content am-cf">
    <div class="row">
        <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
            <div class="widget am-cf">
                <div class="widget-head am-cf">
                    <div class="widget-title am-cf">商品列表</div>
                </div>
                <div class="widget-body am-fr">
                    <div class="page_toolbar am-margin-bottom-xs am-cf">
                        <form class="toolbar-form" action="">
                            <input type="hidden" name="s" value="/<?= $request->pathinfo() ?>">
                            <div class="am-u-sm-12 am-u-md-3">
                                <div class="am-form-group">
                                </div>
                            </div>
                            <div class="am-u-sm-12 am-u-md-9">
                                <div class="am fr">

                                    <div class="am-form-group am-fl">
                                        <?php $status = $request->get('status') ?: null; ?>
                                        <select name="status"
                                                data-am-selected="{btnSize: 'sm', placeholder: '商品状态'}">
                                            <option value=""></option>
                                            <option value="-1"
                                                <?= $status === '-1' ? 'selected' : '' ?>>全部
                                            </option>
                                            <option value="10"
                                                <?= $status == 10 ? 'selected' : '' ?>>上架
                                            </option>
                                            <option value="20"
                                                <?= $status == 20 ? 'selected' : '' ?>>下架
                                            </option>
                                        </select>
                                    </div>
                                    <div class="am-form-group tpl-form-border-form am-fl">
                                        <input type="text" name="start_time"
                                               class="am-form-field"
                                               value="<?= $request->get('start_time') ?>" placeholder="请选择起始日期"
                                               data-am-datepicker>
                                    </div>
                                    <div class="am-form-group tpl-form-border-form am-fl">
                                        <input type="text" name="end_time"
                                               class="am-form-field"
                                               value="<?= $request->get('end_time') ?>" placeholder="请选择截止日期"
                                               data-am-datepicker>
                                    </div>
                                    <div class="am-form-group am-fl">
                                        <div class="am-input-group am-input-group-sm tpl-form-border-form">
                                            <input type="text" class="am-form-field" name="search"
                                                   placeholder="请输入商品名称"
                                                   value="<?= $request->get('search') ?>">

                                            <div class="am-input-group-btn">
                                                <button class="am-btn am-btn-default am-icon-search"
                                                        type="submit"></button>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </form>
                    </div>

                    <div class="am-scrollable-horizontal am-u-sm-12">
                        <table width="100%" class="am-table am-table-compact am-table-striped
                         tpl-table-black am-text-nowrap">
                            <thead>
                            <tr>
                                <th>商品ID</th>
                                <th>商品图片</th>
                                <th>商品名称</th>
                                <th>所属商城</th>
                                <th>实际销量</th>
                                <th>商品排序</th>
                                <th>商品状态</th>
                                <th>添加时间</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            <?php if (!$list->isEmpty()): foreach ($list as $item): ?>
                                <tr>
                                    <td class="am-text-middle" id="<?= $item['goods_id'] ?>"><?= $item['goods_id'] ?></td>
                                    <td class="am-text-middle">
                                        <a href="<?= $item['image'][0]['file_path'] ?>"
                                           title="点击查看大图" target="_blank">
                                            <img src="<?= $item['image'][0]['file_path'] ?>"
                                                 width="50" height="50" alt="商品图片">
                                        </a>
                                    </td>
                                    <td class="am-text-middle">
                                        <p class="item-title" id="<?= $item['goods_name'] ?>"><?= $item['goods_name'] ?></p>
                                    </td>
                                    <td class="am-text-middle">
                                        <p class="item-title"><?= $item['wxapp']['wxapp_name'] ?></p>
                                    </td>

                                    <td class="am-text-middle"><?= $item['sales_actual'] ?></td>
                                    <td class="am-text-middle"><?= $item['goods_sort'] ?></td>
                                    <td class="am-text-middle">
                                    <span class="j-state am-badge x-cur-p
                                           am-badge-<?= $item['goods_status'] == 10 ? 'success' : 'warning' ?>"
                                                 data-id="<?= $item['goods_id'] ?>"
                                                 data-state="<?= $item['goods_status']['value'] ?>">
                                                <?= $item['goods_status'] == 10 ? '上架' : '下架' ?>

                                           </span>
                                    </td>
                                    <td class="am-text-middle"><?= $item['create_time'] ?></td>
                                    <td class="am-text-middle">
                                        <div class="tpl-table-black-operation">

                                            <?php if (checkPrivilege('goods.goods/offdown')): ?>
                                            <?php if  ($item['goods_status']==10): ?>

                                                <a href="javascript:;" class="item-delete js-down tpl-table-black-operation-del"
                                                   data-id="<?= $item['goods_id'] ?>">
                                                    <i class="am-icon-trash"></i>下架
                                                </a>
                                            <?php endif; ?>
                                            <?php endif; ?>

                                        </div>
                                    </td>
                                </tr>
                            <?php endforeach; else: ?>
                                <tr>
                                    <td colspan="9" class="am-text-center">暂无记录</td>
                                </tr>
                            <?php endif; ?>
                            </tbody>
                        </table>
                    </div>
                    <div class="am-u-lg-12 am-cf">
                        <div class="am-fr"><?= $list->render() ?> </div>
                        <div class="am-fr pagination-total am-margin-right">
                            <div class="am-vertical-align-middle">总记录：<?= $list->total() ?></div>
                        </div>
                    </div>

                </div>
            </div>
        </div>
    </div>
</div>
<script>


    $(function () {

        // 商品状态
        $('.js-down').click(function () {
            // 验证权限
            if (!"<?= checkPrivilege('goods.goods/offdown')?>") {
                return false;
            }
            var data = $(this).data();
            var str="<div class=\"row-content am-cf\">\n" +
                "    <div class=\"row\">\n" +
                "        <div class=\"am-u-sm-12 am-u-md-12 am-u-lg-12\">\n" +
                "            <div class=\"widget am-cf\">\n" +
                "                <form id=\"my-form\" class=\"am-form tpl-form-line-form\" method=\"post\">\n" +
                "                    <div class=\"widget-body\">\n" +
                "                        <fieldset>\n" +
                "                            <div class=\"am-form-group\">\n" +
                "                                <label class=\"am-u-sm-3 am-u-lg-2 am-form-label form-require\">消息标题  </label>\n" +
                "                                <div class=\"am-u-sm-9 am-u-end\">\n" +
                "                                    <input type=\"text\" id='title' class=\"tpl-form-input\" name=\"message_title\"\n" +
                "                                           value=\"\" required>\n" +
                "                                </div>\n" +
                "                            </div>\n" +
                "                            <div class=\"am-form-group\">\n" +
                "                                <label class=\"am-u-sm-3 am-u-lg-2 am-form-label form-require\">行业描述 </label>\n" +
                "                                <div class=\"am-u-sm-9 am-u-end\">\n" +
                "                                    <textarea cols=\"100\" rows=\"10\"  id='content' name=\"message_content\"></textarea>\n" +
                "                                </div>\n" +
                "                            </div>\n" +
                "                        </fieldset>\n" +
                "                    </div>\n" +
                "                </form>\n" +
                "            </div>\n" +
                "        </div>\n" +
                "    </div>\n" +
                "</div>";

            layer.confirm(str,{btn: ['确定', '取消'], area:["700px","500px"], title: "下架通知"}, function (index, layero) {
                var title = $(layero).find('#title').val();
                var content = $(layero).find('#content').val();;
                    $.post("<?= url('goods.goods/offdown') ?>"
                        , {
                            goods_id: data.id,
                            message_title:title,
                            message_content:content,
                        }
                        , function (result) {
                            result.code === 1 ? $.show_success(result.msg, result.url) : $.show_error(result.msg);
                        });
                    layer.close(index);
                });
        });



    });

</script>

